#ifndef __CM_NAT_XMPP_CLIENT_H__
#define __CM_NAT_XMPP_CLIENT_H__

#include "Log.h"
#include "loghandler.h"
#include "jid.h"
#include "client.h"
#include "connectionlistener.h"
#include "Jingle.h"

using namespace cm_base;
using namespace cm_xmpp;
using namespace cm_nat;

namespace cm_nat
{
    class XMPPClient;

    class XMPPClientListener
    {
    public:
        virtual void onConnect( XMPPClient* client ) = 0;
        virtual void onDisconnect( XMPPClient* client ) = 0;
    };

    class XMPPClient: public LogHandler,public ConnectionListener
    {
    public:
        XMPPClient( );
        ~XMPPClient();

        void registerListener( XMPPClientListener* p_listener );
        int setup(std::string username, std::string pwd, std::string resource, std::string server, UInt16 serverPort = 5222 );
        int teardown();

        int connect();
        int disconnect();

        ClientBase* getClientBase();

        //from LogHandler
        void handleLog( LogLevel level, LogArea area, const std::string& message );

        //from ConnectionListener
        void onConnect();
        void onDisconnect( int reason );
        bool onTLSConnect(const CertInfo& info );

    private:
        std::string m_username;
        std::string m_server;
        std::string m_resource;
        UInt16 m_serverPort;

        std::string m_password;

        ByteBufferPool m_bufferPool;

        Client * m_client;

        XMPPClientListener* m_listener; 
    };
}

#endif